home *** CD-ROM | disk | FTP | other *** search
- #include "stdg.h"
- #include "bullseye.h"
-
- /* Forward declarations of menu functions */
-
- void close_front(void);
-
- void set_win_width(void);
- void set_win_fore(void);
- void set_win_back(void);
-
- /* Menu state variables */
-
- #define NWIDTHS 11
- #define NCOLOURS 12
-
- short always_enabled = Enabled;
- short can_modify_win = Disabled;
- short can_make_new_win = Enabled;
- short can_close_win = Disabled;
-
- short can_width[NWIDTHS];
- short can_fore[NCOLOURS];
- short can_back[NCOLOURS];
-
- /* Menu definitions */
-
- /* A single pull-down menu is just an array of menuitems.
- * The first menuitem specifies the name of the whole menu.
- * Each menuitem consists of four things:
- * 1. A string which is the name of the menu item.
- * 2. A shortcut key equivalent.
- * 3. The address of a state variable indicating the state of the item.
- * Valid states are Disabled, Enabled, Disabled+Ticked, Enabled+Ticked.
- * 4. The address of a function to call when the item is selected.
- */
-
- menuitem file_menu[] = {
- { "&File", 0, &always_enabled, NULL },
- { "New &Oval", 'O', &can_make_new_win, &new_oval },
- { "New &Rectangle", 'R', &can_make_new_win, &new_rectangle },
- { "New &Triangle", 'T', &can_make_new_win, &new_triangle },
- { "&Close", 'W', &can_close_win, &close_front },
- { "-", 0, NULL, NULL },
- { "&Quit", 'Q', &always_enabled, &gexit },
- { NULL, 0, NULL, NULL }
- };
-
- menuitem edit_menu[] = {
- { "&Edit", 0, &always_enabled, NULL },
- { "&Undo", 'Z', NULL, NULL},
- { "-", 0, NULL, NULL},
- { "Cu&t", 'X', NULL, NULL},
- { "&Copy", 'C', NULL, NULL},
- { "&Paste", 'V', NULL, NULL},
- { "Clea&r", 0, NULL, NULL},
- { "Select &All", 'A', NULL, NULL},
- { NULL, 0, NULL, NULL }
- };
-
- menuitem width_menu[] = {
- { "&Width", 0, &can_modify_win, NULL },
- { "&1", '1', &can_width[1], &set_win_width },
- { "&2", '2', &can_width[2], &set_win_width },
- { "&3", '3', &can_width[3], &set_win_width },
- { "&4", '4', &can_width[4], &set_win_width },
- { "&5", '5', &can_width[5], &set_win_width },
- { "&6", '6', &can_width[6], &set_win_width },
- { "&7", '7', &can_width[7], &set_win_width },
- { "&8", '8', &can_width[8], &set_win_width },
- { "&9", '9', &can_width[9], &set_win_width },
- { "1&0", '0', &can_width[10], &set_win_width },
- { NULL, 0, NULL, NULL }
- };
-
- menuitem fore_menu[] = {
- { "Fo®round", 0, &can_modify_win, NULL },
- { "Blac&k", 0, &can_fore[1], &set_win_fore },
- { "&White", 0, &can_fore[2], &set_win_fore },
- { "&Dark Grey", 0, &can_fore[3], &set_win_fore },
- { "Gr&ey", 0, &can_fore[4], &set_win_fore },
- { "&Light Grey", 0, &can_fore[5], &set_win_fore },
- { "&Red", 0, &can_fore[6], &set_win_fore },
- { "&Green", 0, &can_fore[7], &set_win_fore },
- { "&Blue", 0, &can_fore[8], &set_win_fore },
- { "&Cyan", 0, &can_fore[9], &set_win_fore },
- { "&Magenta", 0, &can_fore[10], &set_win_fore },
- { "&Yellow", 0, &can_fore[11], &set_win_fore },
- { NULL, 0, NULL, NULL }
- };
-
- menuitem back_menu[] = {
- { "Ba&ckground", 0, &can_modify_win, NULL },
- { "Blac&k", 0, &can_back[1], &set_win_back },
- { "&White", 0, &can_back[2], &set_win_back },
- { "&Dark Grey", 0, &can_back[3], &set_win_back },
- { "Gr&ey", 0, &can_back[4], &set_win_back },
- { "&Light Grey", 0, &can_back[5], &set_win_back },
- { "&Red", 0, &can_back[6], &set_win_back },
- { "&Green", 0, &can_back[7], &set_win_back },
- { "&Blue", 0, &can_back[8], &set_win_back },
- { "&Cyan", 0, &can_back[9], &set_win_back },
- { "&Magenta", 0, &can_back[10], &set_win_back },
- { "&Yellow", 0, &can_back[11], &set_win_back },
- { NULL, 0, NULL, NULL }
- };
-
-
- menu menubar[] = {
- file_menu, edit_menu, width_menu, fore_menu, back_menu, NULL
- };
-
-
- /* colours in menu order */
-
- pixval colour_table[] = {
- 0,
- BLACK, WHITE,
- DKGREY, GREY, LTGREY,
- RED, GREEN, BLUE,
- CYAN, MAGENTA, YELLOW
- };
-
- void menuinit(void) /* set menu states so the correct items are enabled */
- {
- int i;
-
- for (i=0; i<NWIDTHS; i++)
- can_width[i] = Enabled;
- for (i=0; i<NCOLOURS; i++)
- can_fore[i] = can_back[i] = Enabled;
- }
-
- short find_colour(pixval v) /* find a colour's menu item number */
- {
- short i;
-
- for (i=1; i<NCOLOURS; i++)
- if (colour_table[i] == v)
- return i;
-
- return 0;
- }
-
- void adjust_menus(void) /* this is called before a menu is displayed */
- {
- window *wp = active_window;
- int i;
-
- for (i = 1; i < NWIDTHS; i++) /* uncheck all the widths */
- can_width[i] = Enabled;
-
- for (i = 1; i < NCOLOURS; i++) { /* uncheck all the colours */
- can_fore[i] = Enabled;
- can_back[i] = Enabled;
- }
-
- if ((wp == NULL) || (wp->flags & Workspace))
- {
- /* there is no frontmost window or it is the workspace window */
-
- can_modify_win = can_close_win = Disabled;
- }
- else if (wp->data != NULL)
- {
- /* the frontmost window is a bullseye window */
-
- can_modify_win = can_close_win = Enabled;
-
- /* check the width and the colours for the frontmost window */
-
- can_width[get_width(wp)] = Enabled + Ticked;
- can_fore[find_colour(get_fore(wp))] = Enabled + Ticked;
- can_back[find_colour(get_back(wp))] = Enabled + Ticked;
- }
- }
-
- /* Menu functions called automatically when the user chooses them */
-
- void close_front(void)
- {
- close(active_window);
- }
-
- void set_win_width(void)
- {
- set_width(active_window, menu_item); /* menu_item is set by the library */
- }
-
- void set_win_fore(void)
- {
- set_fore(active_window, colour_table[menu_item]);
- }
-
- void set_win_back(void)
- {
- set_back(active_window, colour_table[menu_item]);
- }
-